﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace justice.Page
{
    public static class Page<T>
    {
        public static int PageSize = 14;
        /*
        public static List<T> Data(List<T> list, int? pageNum)
        {
            if (pageNum < 1 || pageNum == null)
                pageNum = 1;
            int offset = ((int)pageNum - 1) * PageSize;
            List<T> data = list.Skip(offset).Take(PageSize).ToList();
            return data;
        }
        public static int[] PageData(List<T> list, int? pageNum)
        {
            if (pageNum < 1 || pageNum == null)
                pageNum = 1;
            int pageCount = (int)Math.Ceiling(((decimal)list.Count / PageSize));
            int[] i = new int[] { (int)pageNum, PageSize, pageCount };
            return i;
        }
        */

        public static Dictionary<List<T>,int[]> Data2(List<T> list, int? pageNum)
        {
            if (pageNum < 1 || pageNum == null)
                pageNum = 1;
            int offset = ((int)pageNum - 1) * PageSize;
            List<T> data = list.Skip(offset).Take(PageSize).ToList();
            int pageCount = (int)Math.Ceiling(((decimal)list.Count / PageSize));
            int[] i = new int[] { (int)pageNum, PageSize, pageCount};
            Dictionary<List<T>,int[]> pageData = new Dictionary<List<T>, int[]>();
            pageData.Add(data,i);
            return pageData;
        }
    }
}